import axios from '@/libs/api.request'
import {
  GET_ROLE_LIST,
  PUT_ROLE_LIST,
  B4BUTTON,
  B4BUTTON_SAVE,
  ROLE_PERMISSION_LIST,
  MENU_PERMISSION_SAVE,
  ROLE_EDIT,
  ROLE_ADD,
  ROLE_DELETE
} from './list'

// 角色列表
export const getRoleList = data => {
  return axios.request({
    url: GET_ROLE_LIST,
    params: {
      currentPage: data.page || 1,
      ROLE_ID: data.id,
      showCount: data.size
    },
    method: 'GET'
  })
}

// 修改角色状态
export const changeRoleStatus = data => {
  return axios.request({
    url: PUT_ROLE_LIST,
    params: data,
    method: 'PUT',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 获取增删改查权限
export const getb4Button = data => {
  if (!data.ROLE_ID || !data.MSG) {
    return
  }
  return axios.request({
    url: B4BUTTON,
    params: data,
    method: 'get'
  })
}

// 保存增删改查权限
export const saveb4Button = data => {
  if (!data.ROLE_ID || !data.MSG) {
    return
  }
  return axios.request({
    url: B4BUTTON_SAVE,
    params: data,
    method: 'put'
  })
}

// 获取菜单权限
export const getMenuqx = data => {
  return axios.request({
    url: ROLE_PERMISSION_LIST,
    params: data,
    method: 'get'
  })
}

// 保存菜单权限
export const saveMenuqx = data => {
  return axios.request({
    url: MENU_PERMISSION_SAVE,
    params: data,
    method: 'put'
  })
}

// 编辑角色name
export const editRole = data => {
  return axios.request({
    url: ROLE_EDIT,
    params: data,
    method: 'put',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 新增组、角色
export const addRole = data => {
  return axios.request({
    url: ROLE_ADD,
    params: data,
    method: 'put'
  })
}

// 删除角色
export const deleteRole = data => {
  return axios.request({
    url: ROLE_DELETE,
    params: data,
    method: 'DELETE',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
